//获取文件相关信息
const fs = require("fs");
const path = require("path");
const filePath = path.join(__dirname, "to.txt");

//异步
fs.stat(filePath, (err, stats) => {
    if (err) {
        console.log(err)
    } else {
        console.log(stats)
        console.dir(stats)
    }
});

//同步
let result = fs.statSync(filePath);
if (result.isFile()) {
    console.log('this is a file')
}
if (result.isDirectory()) {
    console.log('this is a directory')
}
console.log(result);